//go:build windows
// +build windows

package server

import (
	"context"

	"gitee.com/hasika/common-server/idispatcher"
	"gitee.com/hasika/common-server/option"
	"gitee.com/hasika/common-server/runtime_server"
	"gitee.com/hasika/gotool/logx"
)

func (s *Server) StartListenAndServe(ctx context.Context, listenOption *option.RemoteOption, dispatcher idispatcher.MessageDispatcher) runtime_server.IRuntimeServer {
	var server runtime_server.IRuntimeServer
	server = runtime_server.NewMultiRoutineServer(ctx, s.option, listenOption, dispatcher)
	go func() {
		listenErr := server.Listen()
		if listenErr != nil {
			logx.Errorf("server %+v listen err: %s", listenOption.Network(), listenErr.Error())
			return
		}
		defer server.Stop()
		startErr := server.Run()
		if startErr != nil {
			logx.Errorf("server %+v run err: %s", listenOption.Network(), startErr.Error())
			return
		}
	}()
	return server
}
